

<?php

class VideoController extends Zend_Controller_Action {

    public function checkAccessKeyParams() {
        $page = $this->_request->getParam("page");
        $appid = $this->_request->getParam("key");
        $sig = $this->_request->getParam("sig");
        
        $ts = $this->_request->getParam("ts");
        $time = time();
        //60s * 15; 
//        if($time - $ts > 60 * 15 || $time - $ts < 0){
//            
//            echo Sunny_ErrorHandled::handleError(Sunny_ErrorHandled::$NO_DATA_RECORD);
//            return;
//        }
        $db = $this->_request->getParam("db");
        if ($db == '1')
            return true;
        if ($appid == "" || $sig == "" || $page == "") {
            echo Sunny_ErrorHandled::handleError(Sunny_ErrorHandled::$INVAILD_PARAMS);
            return false;
        } else {
            if ($appid != Haibl_ConfigData::KEY && $appid != '74523') {
                echo Sunny_ErrorHandled::handleError(Sunny_ErrorHandled::$NOT_FOUND_APIKEY);
                return false;
            } else {
                $params = $this->_request->getParams();
                $requestParams = '';
                foreach ($params as $key => $value) {
                    if ($key != 'controller' && $key != 'action' && $key != 'module' && $key != "sig") {
                        $requestParams.= $key . '=' . $value;
                    }
                }
                $requestParams.= Haibl_ConfigData::ACCESS_KEY;
                $encryptParams = md5($requestParams);

                if ($encryptParams == $sig) {
                    return true;
                } else {
                    echo Sunny_ErrorHandled::handleError(Sunny_ErrorHandled::$NOT_FOUND_APIKEY);
                    if (Haibl_ConfigData::DEBUG) {
                        echo "<p>encryptParams = " . $encryptParams . "</p>";
                    }
                    return false;
                }
            }
        }
    }

    public function girlclipAction() {
        $this->_helper->viewRenderer->setNoRender(true);
        if($this->checkAccessKeyParams()){
            $type = $this->_request->getParam("type") == "" ? 1 : $this->_request->getParam("type");
            $page = $this->_request->getParam("page") == "" ? 1 : $this->_request->getParam("page");
            $count = $this->_request->getParam("count") == "" ? 1 : $this->_request->getParam("count");

            $girl = new Model_Video();
            $data = $girl->get_girl_video_by_page($page, $count,$type, true);
            $returnData['errorId'] = Sunny_ErrorHandled::$DONE;
            $returnData['data'] = $data;

            echo json_encode($returnData);
        }
    }

}
?>

